import React from 'react';
import { TreeSelect } from 'antd';
import { connect } from 'dva';

const { TreeNode } = TreeSelect;

const MemberTree = props => {
  const { data = [props.menus] } = props
  const formatData = d => {
    const data = []
    d.length > 0 && d.map(e => 
      e && e.childList.length > 0 ?
      data.push({ 
        value: e.id,
        key: e.id,
        title: e.name,
        children: formatData(e.childList)
      }) :
      data.push({ 
        value: e.id,
        key: e.id,
        title: e.name,
      })
    )
    return data
  }
  
  return (
    <TreeSelect treeData={formatData(data)} {...props} />
  );
};

export default connect(({global}) => ({
  menus: global.menus,
}))(MemberTree);